//
//  ZRTokenModel.m
//  SinaByOC
//
//  Created by 张锐 on 16/2/29.
//  Copyright © 2016年 zhangr. All rights reserved.
//

#import "ZRTokenModel.h"

@implementation ZRTokenModel

+(instancetype)tokenModelWithDictiorary:(NSDictionary *)dic{

    ZRTokenModel * token = [[ZRTokenModel alloc]init];
    
    [token setValuesForKeysWithDictionary:dic];
    
    return token;

}
//字段不匹配时候不报错
-(void)setValue:(id)value forUndefinedKey:(NSString *)key{}
/**
 *  解归档
 */
- (void)encodeWithCoder:(NSCoder *)aCoder{

    [aCoder encodeObject:self.access_token forKey:@"access_token"];
    [aCoder encodeDouble:self.expires_in forKey:@"expires_in"];
    [aCoder encodeObject:self.uid forKey:@"uid"];
    [aCoder encodeObject:self.screen_name forKey:@"screen_name"];
    [aCoder encodeObject:self.profile_image_url forKey:@"profile_image_url"];
    
}
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder{

    ZRTokenModel * token = [[ZRTokenModel alloc]init];
    
    token.access_token = [aDecoder decodeObjectForKey:@"access_token"];
    token.expires_in = [aDecoder decodeDoubleForKey:@"expires_in"];
    token.uid = [aDecoder decodeObjectForKey:@"uid"];
    token.screen_name = [aDecoder decodeObjectForKey:@"screen_name"];
    token.profile_image_url = [aDecoder decodeObjectForKey:@"profile_image_url"];
    
    return token;

}
/**
 *  保存
 */
-(void)saveWithFileName:(NSString *)fileName{

    NSString * docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    
    NSString * filePath = [docPath stringByAppendingPathComponent:fileName];
    
    [NSKeyedArchiver archiveRootObject:self toFile:filePath];


}

@end
